package net.esj.basic.dao.querybuilder;

import java.io.Serializable;
import java.util.Collection;
import java.util.Map;

import net.esj.basic.utils.hibe.HiCriteria;

import org.hibernate.criterion.MatchMode;

public interface QueryBuilder<T> extends Serializable {

	public abstract QueryBuilder clone();

	/**
	 * 为计数做的clone
	 * @return
	 */
	public abstract QueryBuilder clone4Count();

	public abstract QueryBuilder clone(Class clazz);
	
	/**
	 * 判断是否相等
	 * @param propertyName
	 * @param value
	 */
	public abstract QueryBuilder eq(String propertyName, Object value);

	/**
	 * 判断是否匹配
	 * @param propertyName
	 * @param value
	 */
	public abstract QueryBuilder like(String propertyName, Object value);

	/**
	 * 根据matchMode判断是否匹配
	 * @param propertyName
	 * @param value
	 * @param matchMode
	 */
	public abstract QueryBuilder like(String propertyName, Object value,
			MatchMode matchMode);

	/**
	 * 根据matchMode判断是否匹配
	 * @param propertyName
	 * @param value
	 * @param matchMode
	 */
	public abstract QueryBuilder ilike(String propertyName, Object value,
			MatchMode matchMode);

	/**
	 * 忽略大小写的like搜索
	 * @param propertyName
	 * @param value
	 */
	public abstract QueryBuilder ilike(String propertyName, Object value);

	/**
	 * 判断是否大于
	 * @param propertyName
	 * @param value
	 */
	public abstract QueryBuilder gt(String propertyName, Object value);

	/**
	 * 判断是否小于
	 * @param propertyName
	 * @param value
	 */
	public abstract QueryBuilder lt(String propertyName, Object value);

	/**
	 * 判断是否小于等于
	 * @param propertyName
	 * @param value
	 */
	public abstract QueryBuilder le(String propertyName, Object value);

	/**
	 * 判断是否大于等于
	 * @param propertyName
	 * @param value
	 */
	public abstract QueryBuilder ge(String propertyName, Object value);

	/**
	 * 不等于.
	 * @param propertyName
	 * @param value
	 */
	public QueryBuilder notEq(String propertyName, Object value);

	/**
	 * 判断是否在给定的区间里
	 * @param propertyName
	 * @param lo
	 * @param hi
	 */
	public abstract QueryBuilder between(String propertyName, Object lo,
			Object hi);

	/**
	 * 判断是否在给定的数组里  IN (....)
	 * @param propertyName
	 * @param values
	 */
	public abstract QueryBuilder in(String propertyName, Object[] values);

	/**
	 * 判断是否在给定的集合里
	 * @param propertyName
	 * @param values
	 */
	public abstract QueryBuilder in(String propertyName, Collection values);

	/**
	 * 判断是否为空
	 * @param propertyName
	 */
	public abstract QueryBuilder isNull(String propertyName);

	/**
	 * 判断属性值是否相等
	 * @param propertyName
	 * @param otherPropertyName
	 */
	public abstract QueryBuilder eqProperty(String propertyName,
			String otherPropertyName);

	/**
	 * 判断属性值是否小于
	 * @param propertyName
	 * @param otherPropertyName
	 */
	public abstract QueryBuilder ltProperty(String propertyName,
			String otherPropertyName);

	/**
	 * 判断属性值是否小于等于
	 * @param propertyName
	 * @param otherPropertyName
	 */
	public abstract QueryBuilder leProperty(String propertyName,
			String otherPropertyName);

	/**
	 * 判断是否不等于
	 * @param propertyName
	 */
	public abstract QueryBuilder isNotNull(String propertyName);

	/**
	 * @param propertyNameValues
	 * @return
	 */
	public abstract QueryBuilder allEq(Map propertyNameValues);
	
	/** 
	 * 添加排序:降序
	 * @param orderBy
	 * @return
	 */
	public abstract QueryBuilder OrderByDesc(String propertyName);
	
	/**
	 * 升序
	 * @param propertyName
	 * @return
	 */
	public abstract QueryBuilder OrderByAsc(String propertyName);

	
	/**
	 * 用于语句 not in (a,b,c)/not like ...等中
	 * @param hi
	 * @return
	 */
	public QueryBuilder not(String propertyTable,HiCriteria hi);
	
	/**
	 * eg : id = 1 OR id = 2 OR id >3
	 * 
	 * @param propertyName
	 * @param expressions
	 * @param objects
	 * @return
	 */
	public QueryBuilder or(String propertyName,SymbolExpression expressions, Object[] objects );
	/**
	 * eg : id = 1 OR id = 2 OR id >3
	 * 
	 * @param propertyName
	 * @param expressions
	 * @param objects
	 * @return
	 */
	public QueryBuilder or(String propertyName,SymbolExpression[] expressions, Object[] objects );
	
	/**
	 * eg a.id=0 OR b.name = '123' OR title like '1%'
	 * @param propertyNames
	 * @param expressions
	 * @param objects
	 * @return
	 */
	public QueryBuilder or(String[] propertyNames,SymbolExpression[] expressions, Object[] objects );
	
	public QueryBuilder or(HiCriteria... criterias);
	
	public QueryBuilder or(String subKey,HiCriteria... criterias);
	
	public QueryBuilder fetch(String propertyTable,Object... args);
	
	QueryBuilder setDistinct(String obj);
	
	String getDistinct();
	
	QueryBuilder setProperty(String...objs);
	/***
	 * 获得真实的SQL或Criteria等等 
	 * @param objs
	 * @return
	 */
	public Object invoke(Object... objs);
	
}
